﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;
using WebRamosUC.Models;

namespace WebRamosUC.Controllers
{
    public class CursoController : Controller
    {
        //
        // GET: /Curso/
        //      /Curso/Page/2

        RepositorioCurso repocurso = new RepositorioCurso();
        

        public ActionResult Index(int? page)
        {
            ViewData["Message"] = "Listado de cursos";

            const int pageSize = 25;

            //var cursos = repocurso.AllCursos();
            var cursos = repocurso.AllCursos_orderby_nombre();

            var paginatedCursos = new PaginatedList<Curso>(cursos, page ?? 0, pageSize);

            return View(paginatedCursos);
        }


        //
        // GET: /Curso/Details/5

        public ActionResult Details(string sigla)
        {
            
            Curso curso = repocurso.GetCurso(sigla);

            if (curso == null)
                return View("NotFound");

            else 
                return View(curso);
        }

        //
        // GET: /Curso/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Curso/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Curso/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Curso/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Curso/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Curso/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
               

    }
}
